package com.dh.weibo.controller;

import com.dh.weibo.application.Application;
import com.dh.weibo.dao.UserDao;
import com.dh.weibo.exception.AccountReadyException;
import com.dh.weibo.pojo.User;

import java.util.List;

public class UserController {
    private UserDao userDao = new UserDao();

    public void register(String account, String password, String nickName) throws AccountReadyException {
        User user = new User(account, password, nickName);
        userDao.register(user);
    }

    public User login(String account, String password) {
        return userDao.login(account, password);
    }

    // 返回所有用户
    public List<User> getUsers() {
        return userDao.getUsers();
    }

    /**
     * 冻结用户
     *
     * @param id
     */
    public void freeze(String id) {
        User user = userDao.getUserByID(id);
        if (user != null) {
            if (!user.getUid().equals(Application.user.getUid())) {
                user.setStatus(-1);// 冻结
            }
        }
    }
}
